#include "bitness.h"
#include "executable_file_analyzer.h"

#include <print>
#include <string_view>

int main(int argc, char* argv[])
try
{
    if (argc <= 1)
    {
        std::println("error");
        return -1;
    }

    analyzer::executable_file_analyzer analyzer(argv[1]);
    const auto result = analyzer.analyze();

    for (const auto& import_module : result.import_modules)
    {
        std::println("import module: {}", import_module.name);
        for (const auto& function_name : import_module.functions)
            std::println("{}", function_name);
    }

    constexpr std::string_view info = "is {} {} executable file";
    switch (result.format)
    {
    case analyzer::file_structure::pe:
        std::println(info, "windows", result.bitness == analyzer::x86 ? "x86" : "x64");
        break;
    case analyzer::file_structure::elf:
        std::println(info, "linux", result.bitness == analyzer::x86 ? "x86" : "x64");
        break;
    default:
        std::println("unknown file format");
    }

    return 0;
}
catch (const std::exception& exception)
{
    std::println("error: {}", exception.what());
    return -1;
}
